package frobagroup.controller.frontEnd;

import frobagroup.entities.frontEnd.ShoppingCart;
import frobagroup.pagination.Pagination;
import frobagroup.services.frontEnd.ShoppingCartService;
import frobagroup.utils.Constants;
import frobagroup.utils.ResponseModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by Tinsley on 2018/5/22.
 */
@RequestMapping("/webAPI/shoppingCart")
@RestController
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;


    @RequestMapping(value = "/addOrEditShoppingCart", method = RequestMethod.POST )
    public ResponseEntity<ResponseModel<Object>> addShoppingCart(@RequestBody ShoppingCart shoppingCart,
                                                                 HttpServletRequest request) throws Exception{
        return ResponseModel.success(shoppingCartService.addOrEditShoppingCart(shoppingCart,(String)request.getAttribute("id")),
                Constants.RESPONSE_STATUS_SUCESS);
    }

    @RequestMapping(value = "/removeShoppingCart", method = RequestMethod.POST )
    public ResponseEntity<ResponseModel<Object>> removeShoppingCart(@RequestBody List<String> scIds,
                                                                 HttpServletRequest request) throws Exception{
        return ResponseModel.success(shoppingCartService.removeShoppingCart(scIds,(String)request.getAttribute("id")),
                Constants.RESPONSE_STATUS_SUCESS);
    }

    @RequestMapping(value = "/findShoppingCartList", method = RequestMethod.POST )
    public ResponseEntity<ResponseModel<Object>> findShoppingCartList(@RequestBody Pagination pagination,HttpServletRequest request) throws Exception{
        return ResponseModel.success(shoppingCartService.findShoppingCartList(pagination,(String)request.getAttribute("id")),
                Constants.RESPONSE_STATUS_SUCESS);
    }

    @RequestMapping(value = "/weatherFollow/{id}/{weatherFollow}", method = RequestMethod.POST )
    public ResponseEntity<ResponseModel<Object>> weatherFollow(HttpServletRequest request,
                                                               @PathVariable String id, @PathVariable String weatherFollow
    ) throws Exception{
        return ResponseModel.success(shoppingCartService.weatherFollow(id,(String)request.getAttribute("id"),weatherFollow),
                Constants.RESPONSE_STATUS_SUCESS);
    }


}
